home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_9 / abm.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  804 b   |  30 lines  |  [MATF/MATL]

  1. function [T,Y] = abm(f,T,Y)
  2. % [T,Y] = abm(f,T,Y)
  3. % Adams-Bashforth-Moulton solution for y' = f(t,y) with y(a) = ya.
  4. % f  is the function, input.
  5. % T  is the vector of abscissas, input.
  6. % Y  is the vector of ordinates, input.
  7. % Remark. The first four coordinates of T and Y
  8. % must have starting values obtained with  RK4.m
  9. % T  is the vector of abscissas, output.
  10. % Y  is the vector of ordinates, output.
  11. n = length(T);
  12. if n<5, break, end;
  13. f0 = feval(f,T(1),Y(1));
  14. f1 = feval(f,T(2),Y(2));
  15. f2 = feval(f,T(3),Y(3));
  16. f3 = feval(f,T(4),Y(4));
  17. h  = T(2)-T(1);
  18. h2 = h/24;
  19. a  = T(1);
  20. for k = 4:n-1,
  21.   p = Y(k) + h2*(-9*f0 + 37*f1 - 59*f2 + 55*f3);
  22.   T(k+1) = a + h*k;
  23.   f4 = feval(f,T(k+1),p);
  24.   Y(k+1) = Y(k) + h2*(f1 - 5*f2 + 19*f3 + 9*f4);
  25.   f0 = f1;
  26.   f1 = f2;
  27.   f2 = f3;
  28.   f3 = feval(f,T(k+1),Y(k+1));
  29. end
  30.